package com.jiajian.cm.service.impl;

import com.jiajian.cm.domain.SysBill;
import com.jiajian.cm.mapper.SysBillMapper;
import com.jiajian.cm.service.SysBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SysBillServiceImpl implements SysBillService {

    @Autowired
    //将SysBillMapper传递过来
    private SysBillMapper sysBillMapper;

    @Override
    public List<SysBill> findAllBills(SysBill sysBill) {
        return sysBillMapper.findAllBills(sysBill);
    }

    @Override
    public SysBill findBillById(Long id) {
        return sysBillMapper.findBillById(id);
    }

    @Override
    public Object addBill(SysBill sysBill) {
        //向数据库中添加一条系统账单记录（sysBill）。
        int rows = sysBillMapper.addBill(sysBill);
        return rows > 0 ? sysBill : rows;
    }

    @Override
    //更新一条系统账单记录（sysBill）。
    public int updateBill(SysBill sysBill) {
        return sysBillMapper.updateBill(sysBill);
    }

    @Override
    //删除一条系统账单记录（sysBill）。
    public int deleteBill(Long[] ids) {
        //删除多条数据
        int rows = 0;
        for (Long id : ids) {
            //删除一条数据
            rows += sysBillMapper.deleteBill(id);
        }
        return rows;
    }

    @Override
    //查询所有超时的账单
    public List<SysBill> findTimeoutBill() {
        return sysBillMapper.findTimeoutBill();
    }

}
